package com.hanoiwiki.dao.hibernate;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceException;
import javax.persistence.Query;

import org.springframework.orm.jpa.JpaCallback;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.hanoiwiki.dao.CategorySubTypeDAO;
import com.hanoiwiki.exception.DataAccessException;
import com.hanoiwiki.model.CategorySubType;

@Component
@Transactional
public class CategorySubTypeDAOHibernate extends HibernateBaseDAO<CategorySubType, Integer> implements CategorySubTypeDAO{

	public CategorySubTypeDAOHibernate(Class<CategorySubType> persistenceClass) {
		super(persistenceClass);
		// TODO Auto-generated constructor stub
	}
	
	public CategorySubTypeDAOHibernate() {
		super(CategorySubType.class);
	}

	@SuppressWarnings("rawtypes")
	@Override
	protected com.hanoiwiki.dao.hibernate.HibernateBaseDAO.QueryObject buildQueryObject(
			String selectClause, CategorySubType model) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<CategorySubType> getList() throws DataAccessException {
		StringBuilder strBuilder = new StringBuilder();
		strBuilder.append("SELECT cst FROM CategorySubType cst");
		final String queryStr = strBuilder.toString();
		
		@SuppressWarnings("unchecked")
		List<CategorySubType> results = (List<CategorySubType>)getJpaTemplate().execute(new JpaCallback<Object>() {
			public Object doInJpa(EntityManager em) throws PersistenceException {
				final Query q = em.createQuery(queryStr);
				return q.getResultList();
			}
		});
		
		return results;
	}

}
